<?php
namespace yan\upload;

class UploadDo{
	private $root_path;
	public function __construct($root_path){
		$this->root_path = rtrim($root_path, '/');
	}
	public function save($file, $folder){
		$path = ltrim($folder, '/');
		$path = rtrim($path, '/');
        $file_name =  date('ydm-Hi') . '-' . time() . '.' . $file->extension;
        if(!is_dir($this->root_path . '/'. $path)){
        	@mkdir($this->root_path . '/'. $path);
        }
        $file->saveAs($this->root_path . '/'. $path . '/' . $file_name);
        return $path . '/' . $file_name;
	}
}